#ifndef TCP_SERVER_EPOLLPOLLER_H
#define TCP_SERVER_EPOLLPOLLER_H

#include "../reactor/Poller.h"
#include <vector>

struct epoll_event;

class EPollPoller : public Poller {
private:
    typedef std::vector<struct epoll_event> EventList;
    typedef std::map<int, Channel *> ChannelMap;
    typedef std::vector<Channel *> ChannelList;
public:
    explicit EPollPoller(EventLoop *loop);

    ~EPollPoller() override;

    Timestamp poll(int timeoutMs, ChannelList *activeChannels) override;

    void updateChannel(Channel *channel) override;

    void removeChannel(Channel *channel) override;

private:
    static const int kInitEventListSize = 16;

    static const char *operationToString(int op);

    void fillActiveChannels(int numEvents,
                            ChannelList *activeChannels) const;

    void update(int operation, Channel *channel);

    int epollfd_;
    EventList events_;
};


#endif //TCP_SERVER_EPOLLPOLLER_H
